package com.didispace.chapter56.service.impl;

import com.didispace.chapter56.domain.User;
import com.didispace.chapter56.repository.UserRepository;
import com.didispace.chapter56.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    private UserRepository repository;

    @Autowired
    public void setRepository(UserRepository repository) {
        this.repository = repository;
    }

    @Override
    public User login(String name, String password) {
        return this.repository.findByNameAndPassword(name, password);
    }

    @Override
    public User update(User user) {
        return this.repository.saveAndFlush(user);
    }
}
